package com.ailink.concurrent.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Administrator on 2018/10/22
 */
public class Test {


    public static void main(String[] args) throws InterruptedException {
        Lock lock = new ReentrantLock();
        new Thread(() -> lock.lock()).start();
        Thread.sleep(1000);
        new Thread(() -> lock.lock()).start();
        Thread.sleep(1000);
        new Thread(() -> lock.lock()).start();
//        Thread.sleep(1000);
//        lock.lock();
//        lock.unlock();
    }

    private static class MyThread implements Runnable {

        private Lock lock;

        public MyThread(Lock lock) {
            this.lock = lock;
        }

        @Override
        public void run() {
            this.lock.lock();
            try {
                System.out.println(Thread.currentThread().getName());
            } catch (Exception e) {

            } finally {
                this.lock.unlock();
            }
        }
    }
}
